'''
This module contains functionalities that are commonly re-used
by simple-torrent components.

@author: Hatem Oraby
'''

class TrackerCmds:
    register = "REGISTER"

class TrackerResponse:
    registerResponse = "REGRESPONSE"
    sendeingPeers = "PEER"
    doneSending = "FIN"

class Peer():
    def __init__(self, IP, port):
        self._IP = IP#Check that its a valid IP
        self._port = port #check that its an int and in ports range
        
    def __repr__(self):
        return "Peer: " + self._IP + ":" + str(self._port)
    
    def __eq__(self,peer):
        try:
            return peer._IP == self._IP and peer._port == self._port
        except AttributeError:
            return False
        
    def __hash__(self):
        return hash((self._IP,self._port))
        
    def getAddr(self):
        return self._IP,self._port


    def getIP(self):
        return self._IP
    
    def getPort(self):
        return self._port
